import numpy as np
import cv2

img = cv2.imread('cat.jpg')
m = np.array([0.3, 0, 0.7])  # 数组点乘 最里层与数组相乘 三通道变成单通道
img_grey = np.dot(img, m)

n3 = np.array(img)
n3[:, :, 0] = n3[:, :, 0] * 0.5  # blue
n3[:, :, 1] = n3[:, :, 1] * 0  # green
n3[:, :, 2] = n3[:, :, 2] * 0.5  # red
im = np.sum(n3, axis=2)

grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

print(img[50:53, 50:53, :])
print(img_grey[50:53, 50:53])
print(im[50:53, 50:53])
print(grey[50:53, 50:53])


cv2.imshow('origin', img)
cv2.imshow('origin_gray', img_grey)
# cv2.imshow('im', im)
cv2.imshow('grey', grey)

# gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# blurred = cv2.GaussianBlur(gray, (3, 3), 0)
# xgrad = cv2.Sobel(blurred, cv2.CV_16SC1, 1, 0)
# ygrad = cv2.Sobel(blurred, cv2.CV_16SC1, 0, 1)
# edge_output = cv2.Canny(xgrad, ygrad, 50, 150)
# contours, hierarchy = cv2.findContours(edge_output, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
# cv2.drawContours(img, contours, -1, (0, 255, 0), 1)  # -1表示绘制所有轮廓

# max = 0
# maxA = 0
# for i, contour in enumerate(contours):
#     x, y, w, h = cv2.boundingRect(contour)
#     if w*h>maxA:
#     	max=i
#     	maxA=w*h
# cv2.drawContours(img, contours, max, (0, 0, 255), 2)
# #画框
# x, y, w, h = cv2.boundingRect(contours[max])
# img = cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255,  0), 2)
# cv2.imshow('img', img)


# cv2.imshow('origin', img)
# cv2.imshow('origin_gray', img_grey)
# cv2.imshow('im', im)
# cv2.imshow('xgrad', xgrad)
# cv2.imshow('ygrad', ygrad)
# cv2.imshow('edge_output', edge_output)

# cv2.imshow('mask_red', mask_red)
# cv2.imshow('mask_orange', mask_orange)
# cv2.imshow('mask_red', mask_red)
# cv2.imshow('')


cv2.waitKey()
cv2.destroyAllWindows()
